package ink.lovejinhu.leetcode;

import java.util.HashSet;

/**
 * @author jinhu
 * created 2021-07-22 11:46
 */
public class Solution_0521 {
    /**
     * 最长子序列，不是子串
     *
     * @param a
     * @param b
     * @return
     */
    public int findLUSlength(String a, String b) {
        if (a.length() > b.length()) {
            return a.length();
        } else if (b.length() > a.length()) {
            return b.length();
        } else {
            HashSet<String> ares = this.getAllChild(a);
            HashSet<String> bres = this.getAllChild(b);
            int max = -1;
            for (String v0 : ares
            ) {
                if (bres.contains(v0)) {
                    continue;
                } else {
                    if (v0.length() > max) {
                        max = v0.length();
                    }
                }
            }
            return max;
        }
    }

    public HashSet<String> getAllChild(String a) {
        HashSet<String> res = new HashSet<>();
        for (int i = 0; i < a.length(); i++) {
            for (int j = i + 1; j <= a.length(); j++) {
                res.add(a.substring(i, j));
            }
        }
        return res;
    }
}
